package com.cait.dutyfree.dataaccess.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.cait.dutyfree.dataaccess.AirlineServiceDao;
import com.cait.dutyfree.pojo.Airline;

public class AirlineServiceDaoImpl extends HibernateDaoSupport implements
		AirlineServiceDao {

	@Override
	public List<Airline> getAll() {
		System.out.println("in getting all airlines");
		try {
			ArrayList<Airline> airlines = new ArrayList<Airline>();
			DetachedCriteria criteria = DetachedCriteria
					.forClass(Airline.class);
			@SuppressWarnings("rawtypes")
			List airlineList = getHibernateTemplate().findByCriteria(criteria);

			if ((airlineList != null) && (airlineList.size() > 0)) {
				for (int i = 0; i < airlineList.size(); i++) {
					airlines.add((Airline) airlineList.get(i));
				}
				return airlines;
			}
			return null;
		} catch (Exception e) {
			e.printStackTrace();
			logger.warn("During fetch all products ");
			return null;

		}
	}

}
